package com.wchat.repository;

import com.wchat.dataobject.UserEntity;
import javafx.scene.chart.ValueAxis;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import javax.transaction.Transactional;
import java.util.List;

public interface UserRepository extends JpaRepository<UserEntity,Integer> {

     UserEntity findByPhoneNumber(String phoneNumber);

     @Modifying(clearAutomatically = true)
     @Transactional
     @Query(value = "update user u set u.cute_Name = ?1,u.gender = ?2,u.head_Image = ?3,u.openid = ?4,u.city = ?5,u.province = ?6,u.country = ?7,u.longitude = ?8,u.latitude = ?9 where u.user_Id = ?10",nativeQuery = true)
     int updateByUserId(@Param("cute_Name") String cuteName,@Param("gender") Integer gender,@Param("head_Image") String head_Image,
                               @Param("openid") String openid,@Param("city") String city,@Param("province") String province,@Param("country") String country,
                               @Param("longitude") String longitude,@Param("latitude") String latitude,@Param("userId") Integer userId);

     @Modifying(clearAutomatically = true)
     @Transactional
     @Query(value = "update user u set u.password = ?1 where u.user_Id = ?2",nativeQuery = true)
     int updatePassByUserId(@Param("password") String newPassword,@Param("userId") Integer userId);


     List<UserEntity> findByopenid(String openid);

     @Modifying(clearAutomatically = true)
     @Transactional
     @Query(value = "update user u set u.longitude = ?1,u.latitude = ?2 ,u.gender = ?3 where u.user_Id = ?4",nativeQuery = true)
     int updateUserInfoByUserId(@Param("longitude") String longitude,@Param("latitude") String latitude,@Param("gender") Integer gender,@Param("userId") Integer userId);



     @Modifying(clearAutomatically = true)
     @Transactional
     @Query(value = "update user u set u.cute_Name = ?1,u.gender = ?2,u.head_Image = ?3,u.openid = ?4,u.city = ?5,u.province = ?6,u.country = ?7 where u.user_Id = ?8",nativeQuery = true)
     int updateUser(@Param("cute_Name") String cuteName,@Param("gender") Integer gender,@Param("head_Image") String head_Image,
                        @Param("openid") String openid,@Param("city") String city,@Param("province") String province,@Param("country") String country,
                       @Param("userId") Integer userId);

}









